<?php

require_once VENDOR_PATH . "jpush/autoload.php";

/**
 *极光推送
 */
class JPush {

    private $appkey;
    private $masterSecret;

    public function __construct() {
        $this->appkey='61633a7e010167cdf1faa034';//应用appkey
        $this->masterSecret='224a3d423c40936b88a1ee11';//极光主密码
    }
	/**
	 * 推送
	 */
	public function push($registrationId, $title, $content)
	{
		$client = new \JPush\Client($this->appkey, $this->masterSecret);
		//推送平台
		$platform = ['ios', 'android'];
		$ios      = [
			'sound' => ''
		];
		$android  = [
			'sound' => '',
			'title' => $title,
		];
		$options  = [
			'time_to_live'    => 1,
			'apns_production' => true,
		];
		
		$response = $client
			->push()
			->setPlatform($platform)
			->addRegistrationId($registrationId)
			->setNotificationAlert($content)
			->iosNotification([
				'title' => $title,
				'body'  => $content,
			], $ios)
			->androidNotification($content, $android)
			->options($options)
			->send();
		
		if (isset($response['body']['msg_id']) && $response['body']['msg_id']) {
            return ['code'=>1,'msg'=>'success','data'=>$response['body']];
		} else {
            return ['code'=>0,'msg'=>'failed','data'=>$response['body']];
		}
	}

}